<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	  xmlns:h="http://java.sun.com/jsf/html"
	  xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
	  xmlns:p="http://primefaces.prime.com.tr/ui">
<ui:composition template="/templates/cadastro.xhtml">
	
	<ui:define name="corpo">
		<h:form id="listagem">
			<p:dataTable var="evento" dynamic="true" lazy="true"
			             value="#{eventoHandler.eventos}" 
						 selectionMode="single"
						 rows="7" 
						 paginator="true"
						 style="width: 100%"
			             id= "eventos" 
						 border="1">
				<p:column>
					<f:facet name="header">Id</f:facet>
					<h:outputText value="#{evento.id}"> </h:outputText>
				</p:column>
				<p:column>
					<f:facet name="header">Evento</f:facet>
					<h:outputText value="#{evento.descricao}"> </h:outputText>
				</p:column>
				<p:column>
					<f:facet name="header">Data</f:facet>
					<h:outputText value="#{evento.data}"> </h:outputText>
				</p:column>
				<p:column>
					<f:facet name="header">Operação</f:facet>
					<h:commandLink actionListener="#{eventoHandler.editar}">Editar
						<f:param id="editarEventoParam" name="id" value="#{evento}" />
						<f:ajax execute="@this" render=":edicao" />
					</h:commandLink>
				</p:column>
				<p:column>
					<f:facet name="header">Operação</f:facet>
					<h:commandLink actionListener="#{eventoHandler.excluir}">Excluir
						<f:param id="excluirEventoParam" name="id1" value="#{evento.id}" />
						<f:ajax execute="@this" render=":listagem" />
						<f:ajax execute="@this" render=":edicao" />
					</h:commandLink>
				</p:column>
			</p:dataTable>
		</h:form>
		<br />
		
		<h:form id="edicao">
		<h:outputText rendered="#{eventoHandler.emNavegacao}">
			<h:commandButton action="#{eventoHandler.novo}" value="Novo Evento" />
		</h:outputText>
		<h:outputText rendered="#{eventoHandler.emEdicao}">
			<h:panelGrid columns="2" >
				
				<h:outputLabel value="Evento:" for="descricao" />
				<h:inputText id="descricao" label="descricao"
					value="#{eventoHandler.evento.descricao}" required="true" />
				
				<h:outputLabel value="Data:" />
				<p:calendar id="data" 
	         				pattern="dd/MM/yyyy" 
	         				type = "date"
	         				dateStyle="short"
	         				showOn="button"
	         				value="#{eventoHandler.dataFormatada}" 
	                        valueChangeListener="#{eventoHandler.receberData}" />
				
				<h:outputLabel value="Visibilidade:" />
				<h:selectOneMenu id="visibilidade" 
	                             value="#{eventoHandler.visibilidade}"  
	                             immediate="true"
	                             rendered="true"> 
					<f:selectItems value="#{eventoHandler.visibilidades}" /> 
				</h:selectOneMenu>
				<h:outputText value="&nbsp;" />
				<h:outputText value="&nbsp;" />
				
				<h:outputText value="&nbsp;" />
				<h:commandButton action="#{eventoHandler.salvar}" value="Salvar Dados" />
				
			</h:panelGrid>
			</h:outputText>
			<h:messages style="color: red" />
		</h:form>
	</ui:define>
</ui:composition>
</html>
